package com.tfblog.blog.config;

import com.tfblog.blog.interceptor.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by FengBin on 2021/5/7 14:51
 * 配置类 : 注册拦截器
 */
@Configuration
public class MyTokenInterceptorConfig implements WebMvcConfigurer {


    /*
    * 拦截所有后台页面的请求:
    * 如果是携带@PassToken注解 : 说明是携带账号和密码进行登录,直接通过
    * 如果是携带@userLogin注解 : 说明是携带token令牌进行后台页面的跳转,我们验证token令牌信息来决定是否需要重新登录
    * */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //使用AuthenticationInterceptor拦截器对"/admin"的请求进行拦截进行预处理验证...
        registry.addInterceptor(authenticationInterceptor()).addPathPatterns("/admin/**");
    }


    //注册AuthenticationInterceptor到Spring容器中
    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }
}
